package tdh.xt.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import tdh.xt.entity.vo.ResultDto;
import tdh.xt.enums.CustomResultCode;

@ControllerAdvice
public class MyExceptionHandler {

    static final Logger logger = LoggerFactory.getLogger(MyExceptionHandler.class);

    @ExceptionHandler({NullPointerException.class})
    @ResponseBody
    public ResultDto nullPointerExceptionHandler(NullPointerException e) {
        logger.error("===Null Pointer of:", e);
        return ResultDto.errorOf(CustomResultCode.SERVER_ERROR);
    }

    @ExceptionHandler
    @ResponseBody
    public ResultDto exceptionHandler(Exception e) {
        logger.error("===exception of ", e);
        return ResultDto.errorOf(CustomResultCode.SERVER_ERROR);
    }
}
